package com.apetrenko.avaya.callstore.server;

import com.apetrenko.avaya.callstore.client.Config;
import com.apetrenko.avaya.callstore.client.SettingsService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class SettingsServiceImpl extends RemoteServiceServlet implements SettingsService{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8026029731394212855L;
	private ConfigStorage iConfigStorage;
	
	

	@Override
	public Config getConfig() {
		if (iConfigStorage == null){
			iConfigStorage = (ConfigStorage) this.getServletContext().getAttribute(ContextListener.ATTR_CONFIG_STORAGE);
		}
		return iConfigStorage.load();
	}

	@Override
	public Config setConfig(Config aConfig) {
		if (iConfigStorage == null){
			iConfigStorage = (ConfigStorage) this.getServletContext().getAttribute(ContextListener.ATTR_CONFIG_STORAGE);
		}
		iConfigStorage.store(aConfig);
		return iConfigStorage.load();
	}

}
